//
//  SISSShowView.m
//  SISSAPP
//
//  Created by 优房网 on 2017/7/11.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSShowView.h"

@interface SISSShowView ()

/* leftLabel */
@property (weak, nonatomic) UILabel *leftLabel;
/* rightLabel */
@property (weak, nonatomic) UILabel *rightLabel;
/* bottomLine */
@property (weak, nonatomic) UIView *bottomLine;

@end
@implementation SISSShowView

- (void)setIsShowBottomLine:(BOOL)isShowBottomLine {
    _isShowBottomLine = isShowBottomLine;
    self.bottomLine.hidden = !isShowBottomLine;
}

- (void)setLeftStr:(NSString *)leftStr {
    _leftStr = leftStr;
    if ([[leftStr substringToIndex:1] isEqualToString:@"*"]) {
        NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:leftStr];
        [attributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(0,1)];
        self.leftLabel.attributedText = attributedStr;
    } else {
        self.leftLabel.text = leftStr;
    }
}


- (void)setRightStr:(NSString *)rightStr {
    _rightStr = rightStr;
    self.rightLabel.text = rightStr.length > 0 ? rightStr : @" ";
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    UILabel *leftLabel = [[UILabel alloc] init];
    leftLabel.textColor = SECONDARY_TEXT_COLOR;
    leftLabel.font = [UIFont systemFontOfSize:16];
    [self addSubview:leftLabel];
    self.leftLabel = leftLabel;
    
    UILabel *rightLabel = [[UILabel alloc] init];
    rightLabel.font = [UIFont systemFontOfSize:16];
    rightLabel.textColor = MAIN_TEXT_COLOR;
    rightLabel.text = self.rightStr;
    rightLabel.numberOfLines = 0;
    rightLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:rightLabel];
    self.rightLabel = rightLabel;
    
    UIView *bottomLine = [[UIView alloc] init];
    bottomLine.backgroundColor = [UIColor groupTableViewBackgroundColor];
    bottomLine.hidden = !self.isShowBottomLine;
    [self addSubview:bottomLine];
    self.bottomLine = bottomLine;
    
    // 自动布局
    CGFloat margin = 8.0;
    WeakSelf
    [self.leftLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf);
        make.left.equalTo(weakSelf).offset(2 * margin);
    }];
    
    [self.rightLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.leftLabel.mas_right).offset(2 * margin);
//        make.centerX.equalTo(weakSelf).offset(6 * margin);
//        make.centerY.equalTo(weakSelf);
        make.top.equalTo(weakSelf).offset(2 * margin);
        make.right.equalTo(weakSelf).offset(-2 * margin);
    }];

    [bottomLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.rightLabel.mas_bottom).offset(margin);
        make.left.right.bottom.equalTo(weakSelf);
        make.height.mas_equalTo(1);
    }];
}

@end
